<?php

class ProductPeer extends BaseProductPeer
{
	public static function getTopProducts()
	{
		$criteria = new Criteria();

		$criteria->addDescendingOrderByColumn(self::CLICKS);
		$criteria->setLimit(10);

		return self::doSelect($criteria);
	}

	static public function getLuceneIndex()
	{
	  ProjectConfiguration::registerZend();
 
	  if (file_exists($index = self::getLuceneIndexFile()))
	  {
	    return Zend_Search_Lucene::open($index);
	  }
	  else
	  {
	    return Zend_Search_Lucene::create($index);
	  }
	}
 
	static public function getLuceneIndexFile()
	{
	  return sfConfig::get('sf_data_dir').'/product.index';
	}

	static public function getForLuceneQuery($query)
	{
	  $hits = self::getLuceneIndex()->find($query);
	 
	  $pks = array();
	  foreach ($hits as $hit)
	  {
	    $pks[] = $hit->pk;
	  }
	 
	  $criteria = new Criteria();
	  $criteria->add(self::ID, $pks, Criteria::IN);
	  $criteria->setLimit(20);
	 
	  return self::doSelect($criteria);
	}
}
